package com.hzgj.demo.b;

import com.google.common.collect.Lists;
import com.hzgj.bcl.soa.util.Pair;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;

/**
 * Created by Administrator on 2016/9/22.
 */
@Component
public class BServiceImpl implements BService {

    //    @Autowired
//    private CService cService;
//    @Autowired
//    private FService fService;
    private static AtomicLong count = new AtomicLong(0);

    @Override
    public BRet getServiceFromCF() {
        List<Pair<String, Integer>> data = Lists.newArrayList();
        Random item = new Random();
        int length = item.nextInt(5000);
        for (int i = 0; i < length; i++) {
            data.add(new Pair<>("item_" + i, new Random().nextInt(500)));
        }
//        count.getAndIncrement();
//        if (count.get() % 100 == 0) {
//            throw new RuntimeException("need exception in this time");
//        }

        return new BRet(data, "b", new Date());


    }
//    @Override
//    public BRet getServiceFromCF() {
//        CRet cRet = cService.getServiceFromED();
//        List<Pair<String, Integer>> data = Lists.newArrayList();
//        for (String item : cRet.getData()) {
//            data.add(new Pair<>(item, new Random().nextInt(500)));
//        }
//        String from = fService.getServiceByF();
//        count.getAndIncrement();
//        if (count.get() % 100 == 0) {
//            throw new RuntimeException("need exception in this time");
//        }
//
//        return new BRet(data, "b", new Date());
//
//
//    }
}
